﻿using System;
using System.Collections.Generic;

namespace CustomControls
{
    public class ChatTextLine : IEnumerable<ChatTextBlock>
    {
        List<ChatTextBlock> Text;

        public ChatTextBlock this[int i]
        {
            get { return this.Text[i]; }
        }

        public ChatTextLine()
        {
            this.Text = new List<ChatTextBlock>();
        }

        public ChatTextLine(params ChatTextBlock[] TextBlocks)
            : this()
        {
            this.Text.AddRange(TextBlocks);
        }

        public IEnumerator<ChatTextBlock> GetEnumerator()
        {
            return new ChatTextLineEnum(this.Text);
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return new ChatTextLineEnum(this.Text);
        }

        public char CharAtPosition(int x, int y)
        {
            throw new NotImplementedException();
        }
    }

    public class ChatTextLineEnum : IEnumerator<ChatTextBlock>
    {
        int i = 0;
        List<ChatTextBlock> Blocks;


        public ChatTextLineEnum(List<ChatTextBlock> Line)
        {
            this.Blocks = Line;
            this.i = -1;
        }

        public ChatTextBlock Current
        {
            get { return this.Blocks[i]; }
        }

        public void Dispose()
        {
            this.Blocks = null;
        }

        object System.Collections.IEnumerator.Current
        {
            get { return this.Blocks[i]; }
        }

        public bool MoveNext()
        {
            if (i < this.Blocks.Count - 1)
            {
                this.i++;
                return true;
            }

            return false;
        }

        public void Reset()
        {
            this.i = 0;
        }
    }
}

